matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]]
target = 3
def searchMatrix(matrix,target):
    matrixRowLen=len(matrix)
    matrixColLen=len(matrix[0])
    for i in range(matrixRowLen):
        rowMin,rowMax=matrix[i][0],matrix[i][matrixColLen-1]
        print(rowMin,rowMax)
        if target>=rowMin and target<=rowMax:
            for j in range(matrixColLen):
                if matrix[i][j]==target:
                    return True
        if target<rowMin:
            #我们的目标值比我们检索的部分要小：
            break
    return False

def searchMatrix2(matrix,target):
    matrixRowLen=len(matrix)
    matrixColLen=len(matrix[0])
    for i in range(matrixRowLen):
        rowMin,rowMax=matrix[i][0],matrix[i][matrixColLen-1]
        # print(rowMin,rowMax)
        if target>=rowMin and target<=rowMax:
            left,right=0,matrixColLen-1
            while left<=right:
                mid = (left + right) >> 1
                if target==matrix[i][mid]:
                    return True
                elif target<matrix[i][mid]:
                    right=mid-1
                else:
                    left=mid+1
        if target<rowMin:
            #我们的目标值比我们检索的部分要小：
            break
    return False
print(searchMatrix2(matrix,target))